package com.jerei.utils.condition;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by sunfeihu on 2016/11/3.
 * 条件实体
 */
public class ConditionEntity {

    private Map<String, WhereEntity> wMap = null;

    private Map<String, OrderByEntity> oMap = null;

    private List<WhereEntity> whereEntities;

    private Map<String, WhereEntity> whereEntityMap;

    private Map<String, OrderByEntity> orderByEntityMap;

    private List<OrderByEntity> orderByEntities;

    public List<WhereEntity> getWhereEntities() {
        return whereEntities;
    }

    public void setWhereEntities(List<WhereEntity> whereEntities) {
        this.whereEntities = whereEntities;
    }

    public List<OrderByEntity> getOrderByEntities() {
        return orderByEntities;
    }

    public void setOrderByEntities(List<OrderByEntity> orderByEntities) {
        this.orderByEntities = orderByEntities;
    }

    public Map<String, WhereEntity> getWhereEntityMap() {
        if (null == wMap) {
            if (null != this.getWhereEntities()) {
                wMap = new HashMap<String, WhereEntity>();
                for (WhereEntity we : this.getWhereEntities()) {
                    wMap.put(we.getOp() + "." + we.getField(), we);
                }
            }
        }
        return wMap;
    }

    public Map<String, OrderByEntity> getOrderByEntityMap() {
        if (null == oMap) {
            if (null != this.getOrderByEntities()) {
                oMap = new HashMap<String, OrderByEntity>();
                for (OrderByEntity obe : this.getOrderByEntities()) {
                    oMap.put(obe.getOp() + "." + obe.getOrder(), obe);
                }
            }
        }
        return orderByEntityMap;
    }
}

